package com.hqyj.ssm.dept.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hqyj.ssm.dept.entity.Dept;
import com.hqyj.ssm.dept.service.DeptService;

@Controller
public class DeptController {
	@Autowired
	private DeptService deptService;
	
	@RequestMapping("list.do")
	public String listDept(ModelMap map) {
		List<Dept> depts = deptService.selectDepts();
		map.put("depts", depts);
		return "jsp/listDept";
	}
	
	@RequestMapping("delete.do")
	public String deleteDept(String id) {
		String row = deptService.delete(Integer.parseInt(id));
		
		return "redirect:/list.do";
	}
	@RequestMapping("toadd.do")
	public String toadd() {
		return "jsp/addDept";
	}
	
	@RequestMapping("add.do")
	public String addDept(Dept dept) {
		String row = deptService.addDept(dept);
		return "redirect:/list.do";
	}
	@RequestMapping("getDept.do")
	public String getDept(String id,ModelMap map) {
		Dept dept = deptService.getDept(Integer.parseInt(id));
		map.put("dept", dept);
		return "jsp/modifyDept";
	}
	
	@RequestMapping("update.do")
	public String updateDept(Dept dept) {
		String row = deptService.updateDept(dept);
		
		return "redirect:/list.do";
	}

}
